/**
 * @file   1053.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sat Apr 17 00:01:38 2021
 * 
 * @brief  Problem 1053:Find the weight!
 * 
 * 
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int path[110];
//Using adjacent table to give the information of tree
class Tree{
private:
    vector<vector<int>> AdjTable;
    map<int,int> NodeWeight;
    int nodenum;
    int nonleafnum;
    int targetweight;
    vector<int> pathweight;//the weight of nodes in the current path
public:
    Tree(int _nodenum,int _nonleafnum,int _targetweight){
	nodenum=_nodenum;
	nonleafnum=_nonleafnum;
	targetweight=_targetweight;
	AdjTable.resize(nodenum);//determine the size of table!
    }
    void setweight();
    void setAdjTable();
    void Sort(int i);
    void DFS();//Deep First Search
    void deepfirst(int index,int numnode,int sum);
    void printseq(){
	for(auto it=pathweight.begin();it!=pathweight.end();it++){
	    if(it==pathweight.begin()){
		cout<<(*it);
	    }else{
		cout<<" "<<(*it);
	    }
	}
	cout<<endl;
    }
};
void Tree::setweight(){
    int w;
    for(int i=0;i<nodenum;i++){//set weight for all the tree nodes!
	cin>>w;
	NodeWeight[i]=w;
    }
}
void Tree::setAdjTable(){
    for(int i=0;i<nonleafnum;i++){
	int front;
	int num;
	int data;
	cin>>front>>num;
	for(int j=0;j<num;j++){
	    cin>>data;
	    AdjTable[front].push_back(data);
	}
	Sort(i);
    }
}
void Tree::Sort(int i){//Sort the adjtable[i];
    for(int j=0;j<AdjTable[i].size();j++){
	int flag=j;
	for(int k=j;k<AdjTable[i].size();k++){
	    if(NodeWeight[AdjTable[i][k]]>NodeWeight[AdjTable[i][flag]]){
		flag=k;
	    }
	}
	swap(AdjTable[i][j],AdjTable[i][flag]);
    }
}
void Tree::DFS(){
    deepfirst(0,1,NodeWeight[0]);
}
void Tree::deepfirst(int index,int numnode,int sum){
    if(sum>targetweight){//wrong!
	return;
    }else if(sum==targetweight){
	if(AdjTable[index].size()>0){
	    return;   
	}
	for(int i=0;i<numnode;i++){
	    cout<<NodeWeight[path[i]];
	    if(i<numnode-1){
		cout<<" ";
	    }else{
		cout<<endl;
	    }
	}
	return;
    }
    for(int i=0;i<AdjTable[index].size();i++){
	int child=AdjTable[index][i];
	path[numnode]=child;
	deepfirst(child,numnode+1,sum+NodeWeight[child]);
    }
}
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    Tree T(a,b,c);
    T.setweight();
    T.setAdjTable();
    path[0]=0;
    T.DFS();
};
